package test;
import java.util.*;
public class Main3 {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		while(in.hasNext()){
			String str = in.nextLine();
			GeneralStack stack = new ArrayListGeneralStack();
			if(str.equals("Integer")){				
				GeneralStack<Integer> stack1 = new ArrayListGeneralStack<Integer>();
				int sum = 0, m = in.nextInt(), n = in.nextInt();
				System.out.println("Integer Test");					 
				for (int i = 0; i < m; i++) System.out.println("push:"+stack1.push(in.nextInt()));		
				for (int i = 0; i < n; i++) System.out.println("pop:"+stack1.pop());					
				System.out.println(stack1);	
				for (int i = 0; i < m-n; i++) sum += stack1.pop();
				System.out.println("sum="+ sum);
				System.out.println(stack1.getClass().getInterfaces()[0]);
			}
			else if(str.equals("Double")){						
				double sum = 0.0;
				int m = in.nextInt(),n = in.nextInt();
				GeneralStack<Double> stack2 = new ArrayListGeneralStack<Double>();	
				System.out.println("Double Test");					 
				for (int i = 0; i < m; i++) System.out.println("push:"+stack2.push(in.nextDouble()));			
				for (int i = 0; i < n; i++) System.out.println("pop:"+stack2.pop());			
				System.out.println(stack2);
				for (int i = 0; i < m-n; i++) sum += stack2.pop();				
				System.out.println("sum="+sum);
				System.out.println(stack2.getClass().getInterfaces()[0]);
			}
			else if(str.equals("Car")){
				int m = in.nextInt(), n = in.nextInt();
				GeneralStack<Car> stack3 = new ArrayListGeneralStack<Car>();
				System.out.println("Car Test");					 
				for (int i = 0; i < m; i++) {
					Car car = new Car();
					car.setId(in.nextInt());
					car.setName(in.next());
					System.out.println("push:"+stack3.push(car));
				}
				for (int i = 0; i < n; i++) System.out.println("pop:"+stack3.pop());			
				System.out.println(stack3);
				for (int i = 0; i < m-n; i++) System.out.println(stack3.pop().getName());				
				System.out.println(stack3.getClass().getInterfaces()[0]);
			}
			else if(str.equals("quit"))  break;
		}in.close();
	}
		
}
interface GeneralStack<T>{
	public T push(T item); 
	public T pop();      
	public T peek();      
	public boolean empty();
	public int size();    
}

class ArrayListGeneralStack<T> implements GeneralStack<T>{
	private ArrayList<T> list;
	public ArrayListGeneralStack() {
		list = new ArrayList<T>(); 
	}
	
	 @Override
	public String toString() {
		return list.toString();
	}

	@Override
	public T push(T item) {
		if(item==null)  return null;
		list.add(item);
		return item;
	}

	@Override
	public T pop() {  
		if(list.isEmpty()) return null;
		return list.remove(list.size()-1);
	}

	@Override
	public T peek() {
		if(list.isEmpty()) return null;
		return list.get(list.size()-1);		
	}

	@Override
	public boolean empty() {
		if(list.isEmpty()) return true;
		return false;
	}

	@Override
	public int size() {
		return list.size();
	}
}

class Car{
	private int id;
	private String name;
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String toString() {
		return "Car [id=" + id + ", name=" + name + "]";
	}
}






